<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>后台管理_编辑文章</title>
    <link rel="stylesheet" href="/css/bootstrap.min.css">
    <script src="/js/jquery-2.0.3.min.js" type="text/javascript"></script>
    <script src="/js/jquery.validate.min.js" type="text/javascript"></script>
    <script src="/js/messages_bs_zh.js" type="text/javascript"></script>
    <script src="/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/kindeditor/themes/default/default.css" />
    <script charset="utf-8" src="/kindeditor/kindeditor-min.js"></script>
    <script charset="utf-8" src="/kindeditor/lang/zh_CN.js"></script>
</head>
<body>
<script language="JavaScript">
    $(document).ready(function(){
        $('#article-form').validate({
            rules: {
                title: {
                    required: true
                },
                author: {
                    required: true
                },
                source: {
                    required: true
                },
                content: {
                    required: true
                }
            },
            highlight: function(element) {
                $(element).closest('.form-group').removeClass('has-success').addClass('has-error');
            },
            success: function(element) {
                element
                        .addClass('valid')
                        .closest('.form-group').removeClass('has-error').addClass('has-success');
            },
            errorPlacement: function(error, element) {
                error.appendTo( element.parent("div").next("div") );
            },
            errorClass: "control-label"
        });
    });
    var editor;
    KindEditor.ready(function(K) {
        editor = K.create('textarea[name="content"]', {
            resizeType : 1,
            allowPreviewEmoticons : false,
            uploadJson : "/uploadImage.do",
            items : [
                'source', '|', 'undo', 'redo', '|', 'preview','cut', 'copy', 'paste',
                'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
                'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
                'insertunorderedlist', '|',  'image', 'link']
        });
    });
    function updateSchool(){
        if($("#category").val()==5)
            $("#school_div").removeClass("hidden");
        else {
            $("#school_div").addClass("hidden");
            $("#schoolId").val(0);
        }
    }
</script>
<div class="container" >
    <div class="row">
        <div class="col-md-4"></div>
        <div class="col-md-8">
            <ul class="nav nav-pills" >
                <li><a href="/man/school/list">学校管理</a> </li>
                <li class="active"><a href="/man/article/list">文章管理</a></li>
                <li><a href="/man/apply/list">报名管理</a></li>
            </ul>
        </div>
    </div>
    <p class="lead"></p>
    <form:form action="/man/article/save"  cssClass="form-horizontal" id="article-form"  method="post" modelAttribute="article">
        <input type="hidden" name="id" value="${article.id}">
        <div class="form-group">
            <label for="title" class="col-sm-4 control-label">标题</label>
            <div class="col-sm-5">
                <input type="text" class="form-control" id="title"  name="title" value="${article.title}">
            </div>
            <div class="col-sm-3"></div>
        </div>
        <div class="form-group">
            <label for="category" class="col-sm-4 control-label">文章类别</label>
            <div class="col-sm-5">
                <form:select path="category" items="${categorys}"  cssClass="form-control" id="category" onchange="updateSchool()"/>
            </div>
            <div class="col-sm-3"></div>
        </div>
        <div class="form-group<c:if test="${article.category!=5}"> hidden</c:if>" id="school_div">
            <label for="schoolId" class="col-sm-4 control-label">学校</label>
            <div class="col-sm-5">
                <form:select path="schoolId" items="${schools}" itemLabel="name" itemValue="id" id="schoolId" cssClass="form-control"/>
            </div>
            <div class="col-sm-3"></div>
        </div>
        <div class="form-group">
            <label for="author" class="col-sm-4 control-label">作者</label>
            <div class="col-sm-5">
                <input type="text" class="form-control" id="author"  name="author" value="${article.author}">
            </div>
            <div class="col-sm-3"></div>
        </div>
        <div class="form-group">
            <label for="source" class="col-sm-4 control-label">来源</label>
            <div class="col-sm-5">
                <input type="text" class="form-control" id="source"  name="source" value="${article.source}">
            </div>
            <div class="col-sm-3"></div>
        </div>
        <div class="form-group">
            <label for="content"  class="col-sm-4 control-label">内容</label>
            <div class="col-sm-5">
                <textarea name="content" class="form-control" id="content">${article.content}</textarea>
            </div>
            <div class="col-sm-3"></div>
        </div>
        <div class="form-group">
            <div class="col-sm-offset-5 col-sm-7">
                <button type="submit" class="btn btn-primary">保存</button>
            </div>
        </div>
    </form:form>
</div>

</body>
</html>